package com.lee.common.utils;

import java.util.Calendar;

/**
 * Author Liqiubo
 * desripbe 限制重复点击事件
 */
class OneClickUtil {

    private String methodName;
    private static final int MIN_CLICK_DELAY_TIME = 500;
    private long lastClickTime = 0;

    OneClickUtil(String methodName) {
        this.methodName = methodName;
    }

    public String getMethodName() {
        return methodName;
    }

    public boolean check() {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            return false;
        } else {
            return true;
        }
    }

    public boolean check(int clickTime) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > clickTime) {
            lastClickTime = currentTime;
            return false;
        } else {
            return true;
        }
    }

}
